use std::sync::Arc;

use axum::{extract::State, Json};

use crate::{
    db,
    handler::{get_conn, log_error, Response},
    model, AppState, Result,
};

pub async fn index(
    State(state): State<Arc<AppState>>,
    // RequiredAuth(claims): RequiredAuth<AdminClaimsData>,
) -> Result<Json<Response<Vec<model::aggregation::Summary>>>> {
    let handler_name = "admin/aggregation/index";
    let conn = get_conn(&state);

    let data = db::aggregation::summary(&*conn)
        .await
        .map_err(log_error(handler_name))?;

    Ok(Response::ok(data).to_json())
}
